content = '''
#什么是码位：
>>> '你好呀'.encode("unicode_escape").decode()
'\\u4f60\\u597d\\u5440'
>>> '\u4f60\u597d\u5440'
'你好呀'

#编码：
>>> "你好呀".encode("utf-8")
b'\xe4\xbd\xa0\xe5\xa5\xbd\xe5\x91\x80'

#解码：
>>> b = "你好呀".encode("utf-8")
>>> b.decode("utf")
'你好呀'

#检测编码：
>>> import chardet
>>> chardet.detect(b)
{'encoding': 'utf-8', 'confidence': 0.87625, 'language': ''}

#忽略错误编码：
>>> b_2 = "你好呀".encode("utf-8")+"我很好".encode("gbk")
>>> b_2
b'\xe4\xbd\xa0\xe5\xa5\xbd\xe5\x91\x80\xce\xd2\xba\xdc\xba\xc3'
>>> b_2.decode("utf-8", errors='ignore')
'你好呀Һܺ'

#利用鬼符来替换：
>>> b_2.decode("utf-8", errors='replace')
'你好呀�Һܺ�'

#字符串的CRUD操作：
#Create
>>> a = "Hello World!"
>>> id(a)
2333141953392
>>> a += "I am Macintosh"
>>> id(a)
2333141149216
>>> a
'Hello World!I am Macintosh'

#Retrieve
>>> a[10]
'd'
>>> a.find("Macintosh")
17
>>> a.index("M")
17
>>> a.find("m")
15
>>> a.startswith("hello")
False
>>> a.startswith("Hello")
True
>>> a.endswith("s")
False
>>> a.endswith("h")
True

#Update
>>> a.replace("I am", "My name is")
'Hello World!My name is Macintosh'
>>> a.split("!")
['Hello World', 'I am Macintosh']
>>> b = a.split("!")
>>> ".".join(b)
'Hello World.I am Macintosh'

#Delete
>>> c = "         Hello, World!!     "
>>> c.strip()
'Hello, World!!'
>>> c.rstrip()
'         Hello, World!!'
>>> c.lstrip().lstrip('Hello')
', World!!     '

#字符串格式化输出
>>> a = "China"
>>> b = "Chendu"
>>> "come to {} {}".format(a,b)
'come to China Chendu'
>>> "come to {0} {1} {1} {0}".format(a,b)
'come to China Chendu Chendu China'
>>> "come to {c} {d} {d} {c}".format(c='china',d='chengdu')
'come to china chengdu chengdu china'
>>> print(f"come {a} {b}")
come China Chendu
>>> "{:.2f}".format(3.1415926)
'3.14'
>>> "let's go to %s" % ("Shanghai!")
"let's go to Shanghai!"

'''
fw = open("第二周_第二节课_输出文件.txt", "w", encoding="utf-8")
fw.write(content)
fw.close()